package com.ysd.lis.mapper.sys;

import com.github.yulichang.base.MPJBaseMapper;
import com.ysd.common.dto.ColumnAndCommentDto;
import com.ysd.common.dto.ColumnValueDto;
import com.ysd.common.sqlbuilder.TransmitSqlBuilder;
import com.ysd.lis.entity.SysBasDictTable;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * cold_chain.t_user Mapper 接口
 * </p>
 *
 * @author peng
 * @since 2021-10-08
 */
public interface SysBasDictTableMapper extends MPJBaseMapper<SysBasDictTable> {

    /**
     * 查询表字段
     *
     * @param tableName
     * @return
     */
    @SelectProvider(type = TransmitSqlBuilder.class, method = "buildSelectColumnsByTableName")
    List<ColumnAndCommentDto> findColumnsByTableName(@Param("tableName") String tableName);


    @Select("Select * from ${tableName}")
    List<Map> getTableDataByTableName(@Param("tableName") String tableName);

    @UpdateProvider(type = TransmitSqlBuilder.class, method = "buildUpdateTransmitTodoSql")
    int updateTransmitTodoTable(@Param("tableName")String tableName, @Param("list") List<ColumnValueDto> list);

    /**
     * 动态查询模板实例表
     *
     * @param tableName
     * @return
     */
    @SelectProvider(type = TransmitSqlBuilder.class, method = "buildSelectTransmitTodoSql")
    List<Map<String, Object>> getTransmitTodoData(@Param("tableName") String tableName, @Param("columnList") List<String> columnList);

    /**
     * 动态查询模板实例表
     *
     * @param tableName
     * @return
     */
    @SelectProvider(type = TransmitSqlBuilder.class, method = "buildSelectTransmitTodoSqlByBusiness")
    List<Map<String, Object>> getTransmitTodoDataByBusiness(@Param("tableName") String tableName,
                                                            @Param("outField") String outField,
                                                            @Param("indexCode") String indexCode,
                                                            @Param("itemCode") String itemCode,
                                                            @Param("majorCode") String majorCode,
                                                            @Param("moduleType") String moduleType,
                                                            @Param("columnList") List<String> columnList,
                                                            @Param("keywords")String keywords);
    /**
     * 动态查询模板实例表
     *
     * @param tableName
     * @return
     */
    @SelectProvider(type = TransmitSqlBuilder.class, method = "buildSelectTransmitTodoSqlByMajor")
    List<Map<String, Object>> getTransmitTodoDataByMajorBusiness(@Param("tableName") String tableName,
                                                            @Param("outField") String outField,
                                                            @Param("moduleType") String moduleType,
                                                            @Param("columnList") List<String> columnList,
                                                            @Param("keywords")String keywords);

    /**
     * 新增模版实例
     *
     * @param tableName
     * @param list
     * @return
     */
    @InsertProvider(type = TransmitSqlBuilder.class, method = "buildInsertTransmitTodoSql")
    int insertTransmitTodoTable(@Param("tableName") String tableName, @Param("list") List<ColumnValueDto> list);

    /**
     * 动态删除数据
     *
     * @param tableName
     * @param id
     * @return
     */
    @Delete("delete from ${tableName} where id = #{id}")
    boolean deleteDynamicTableData(@Param("tableName") String tableName, @Param("id") String id);

    @Select("Select max(SUBSTR(${column}, ${suffLeth}*-1, ${suffLeth})) as VALUE from ${tableName} where ${column} like '%${fixText}%'")
    String selectColumnValueByRuleTodoTable(@Param("tableName")String tableName,@Param("column") String column,@Param("suffLeth") Integer suffLeth,@Param("fixText") String fixText);

    @SelectProvider(type = TransmitSqlBuilder.class, method = "buildFindTableNamesSql")
    List<Map<String, String>> findTableNames(@Param("tableName") String tableName);
}
